<api>
  <links>
<?php
$db = new SimpleXMLElement(file_get_contents("database.xml"));
foreach($db->pages->page as $page) {
  $text = $page->revision[count($page->revision)-1];
  $numwords = count(split(" ",$text));
  $revisions = count($page->revision);
  echo "    <page title='".$page['title']."' words='$numwords' revisions='$revisions'>\n";
  $split = split("}",$text);
  for($i=0; $i<count($split)-1; $i++) {
    $segment = $split[$i];
    $split2 = split("{",$segment);
    $final .= $split2[0];
    $linktarget = $split2[1];
    $linkbase = $page['title'];
    /*    
    // add to db
    $link = $db->links->addChild("link");
    $link['to'] = $linkbase;
    $link['from'] = $linktarget;
    */
    echo "      <link to='".$linktarget."' />\n";
  }
  echo "    </page>\n";
}
?>
  </links>
</api>